<?php
/**
 * Core_Model_View
 * view model
 * @author Adrian Stolarski
 */
class Core_Model_View implements Core_Model_Viewable, Core_Model_Renderable, Core_Model_Datacheckoutable {
    
    
    public function view(array $data = null, $template = null, $key = null) {
        $template = $this->render($template);
        $data = $this->data_checkout($data);
        $assing_data = new Core_Data_Viewdata;
        $new_data = $assing_data->assign($key, $data);
        $file_to_load = new Core_Data_Fileloader;
        $file_to_load->load_file($template);
        
    }

    /**
     * render()
     * check template is exists
     * @param type $file_name
     * @return type $template
     * @throws Exception
     */
    public function render($template) {
        try {
            if(file_exists($template)){
                return $template;
            }
            else {
                $message = new Core_Data_Filenotexists;
                throw new Exception($message->message($template));
            }
        } catch (Exception $exception) {
            echo $exception->getMessage();
        }
    }

    /**
     * data_checkout()
     * array is not null
     * 
     * @param array $variables
     * @return array $variables
     */
    public function data_checkout(array $variables = null) {
        if($variables != null){
            return $variables;
        }
    }

}
